<?php
namespace app\index\controller;

class Index extends Base
{
    public function index()
    {
        $category_model = model('category');

        //首页轮播广告
        $advert = new \app\admin\model\Advert();
        
        $data_advert = $advert->where('typeid', 1)->select();

        $this->assign('data_advert', $data_advert);
        
        // 设计案例
        $cpid = 37;

        $category_example = $category_model->where('pid', $cpid)->column('id, name');

        $this->assign('category_example', $category_example);

        $cids = $category_model->where('pid', $cpid)->column('id');

        $example = new \app\admin\model\Example();

        $data_example = $example->where('cid', 'in', $cids)
            ->where('status', 1)
            ->order('id desc, top')
            ->limit(10)
            ->select();

        $this->assign('data_example', $data_example);

        // //工艺展示
        $cid = 42;
        
        $technology = new \app\admin\model\Technology();

        $data_technology= $technology->where('status', 1)
            ->order('id desc, top')
            ->limit(6)
            ->select();
        
        $this->assign('data_technology', $data_technology);

        //鸿锦动态
        $cid = 72;

        $news = new \app\admin\model\News();

        $data_news = $news->field('id,title,summary,mtime')
            ->where('status', 1)
            ->limit(4)
            ->order('id desc, top, sort desc')
            ->select();
      
        $this->assign('data_news', $data_news);

        // 设计团队
        $cpid = 61;

        $cids = $category_model->where('pid', $cpid)->column('id');

        $designer = new \app\admin\model\Designer();

        $data_designer = $designer->where('cid', 'in', $cids)
            ->field('id,name,photograph')
            ->order('top')
            ->select();

        $this->assign('data_designer', $data_designer);

        //在施工地
        $build = new \app\admin\model\Build();
        $cid = 53;

        $data_building = $build->where(['status'=>1, 'cid'=>$cid])
            ->limit(10)
            ->order('id desc, top, sort desc')
            ->select();

        $this->assign('data_building', $data_building);

        // 鸿锦动态

        // 办公空间展示

        $office = new \app\admin\model\Office();

        $data_office = $office->where('isdel', '<>', 1)->order('sort desc')->limit(5)->select();

        $this->assign('data_office', $data_office);

        //主材联盟
        $material = new \app\admin\model\Material();
        $cid = 71;
        
        $data_material = $material->where('status', 1)
            ->limit(5)
            ->order('id desc, top')
            ->select();

        $this->assign('data_material', $data_material);

        return $this->fetch();
    }
}
